package com.xszx.business.controller.admin;

import com.xszx.server.dto.AjaxJson;
import com.xszx.server.dto.Page;
import com.xszx.server.entity.Teacher;
import com.xszx.server.service.TeacherService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;

@RestController
@RequestMapping("/teacher")
@Api(tags = "讲师管理")
public class TeacherController {
    @Resource
    private TeacherService teacherService;

    @GetMapping("/getAll")
    public AjaxJson getAll(){
        return AjaxJson.success().put("teachers", teacherService.getAll());
    }

    @PostMapping("/getAllTeachers")
    public Page getAllTeachers(@RequestBody Page page){
        return teacherService.getAllTeachers(page);
    }

    @GetMapping("/getTeacher")
    public AjaxJson getTeacher(String id){
        return AjaxJson.success().put("teachers",teacherService.getTeacher(id));
    }

    @PostMapping("/save")
    public AjaxJson save(@RequestBody Teacher teacher){
        return AjaxJson.success(teacherService.saveOrUpdate(teacher));
    }

    @ApiIgnore
    @GetMapping("/deleteTeacher")
    public AjaxJson deleteTeacher(String id){
        int result = teacherService.del(id);
        if(result>0){
            return AjaxJson.success("删除成功");
        }else{
            return AjaxJson.error("删除失败");
        }
    }
}
